class PlayController < ApplicationController
  def start
    @game = Game.create(:player1 => "human", :player2 => "human")
    redirect_to :action => :game, :id => @game, :token => @game.token
  end
  
  def game
    @game = Game.find(params[:id])
    
    if @game.token != params[:token]
      flash[:error] = "Invalid game, it is not your turn"
      redirect_to :action => "index" and return
    end
    
  rescue ActiveRecord::RecordNotFound
    flash[:error] = "Game not found"
    redirect_to :action => "index"
  end
end
